package com.itheima.dubbo.mongodb.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.commons.pojo.Publish;
import com.itheima.commons.pojo.TimeLine;
import com.itheima.dubbo.interfaces.PublishApi;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class PublishApiImpl implements PublishApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public String publish(Publish publish) {
        // 直接往发布表中添加一条记录就可以了,返回发布的圈子的主键
        Publish put = mongoTemplate.save(publish);
        return put.getId().toHexString();
    }

    @Override
    public List<Publish> findFriendMovements(Integer page, Integer pagesize, Long userId) {
        // 查询自己的时间线表

        // 根据上面的圈子id去查询发布表
    }

    @Override
    public List<Publish> findMovementsByPids(List<Long> pids) {
        // 从MongoDB去查询
    }

    @Override
    public List<Publish> randomMovements(Integer pagesize) {
        // 从MongoDB中随机抽样数据
    }
}
